package com.jzoom.zoom.admin.controllers;

import com.jzoom.zoom.admin.models.PluginDao;
import com.jzoom.zoom.common.annotations.Inject;
import com.jzoom.zoom.dao.Dao;
import com.jzoom.zoom.plugin.services.PluginService;
import com.jzoom.zoom.web.annotations.Controller;
import com.jzoom.zoom.web.annotations.JsonResponse;
import com.jzoom.zoom.web.annotations.Mapping;
import com.jzoom.zoom.web.annotations.Param;
import com.jzoom.zoom.web.exception.StatusException;

import java.util.Map;

@Controller(key = "sys/sys_plugin")
public class PluginController extends BaseDaoController<PluginDao> {

	@Inject(value = "admin")
	private Dao dao;

	@Inject
	private PluginService pluginService;

	@Mapping(value = "install/{id}", method = Mapping.POST)
	@JsonResponse
	public void install(@Param(name = "{id}") String id) throws StatusException.ApiError {
		pluginService.install(id);
	}

	@Mapping(value = "active/{id}", method = Mapping.POST)
	@JsonResponse
	public void startup(@Param(name = "{id}") String id) throws StatusException.ApiError {
		pluginService.startup(id);
	}
	
	@Mapping(value = "deactive/{id}", method = Mapping.POST)
	@JsonResponse
	public void deactive(@Param(name = "{id}") String id) throws StatusException.ApiError {
		pluginService.shutdown(id);
	}

	@Mapping(value = "uninstall/{id}", method = Mapping.POST)
	@JsonResponse
	public void uninstall(@Param(name = "{id}") String id) throws StatusException.ApiError {
		pluginService.uninstall(id);
	}
	/**
	 * 新增
	 * @param data
	 */
	@JsonResponse
	@Mapping(value="add",method= {Mapping.POST})
	@Override
	public void add(
			@Param(body=true)
			Map<String, Object> data) {
		String uri = (String) data.get("uri");
		pluginService.add( uri );
	}

}
